﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System.Windows.Controls;
using System.ComponentModel;

using MissedMemo.MeatAndCheeseDisc.OrderEntry.OrderProcessing;


namespace MissedMemo.MeatAndCheeseDisc.OrderEntry
{
    public partial class DeliveryOptionsSelector : UserControl
    {
        public readonly static string DriverUndefined = "( Unassigned )";

        public DeliveryOptionsSelector()
        {
            InitializeComponent();

            DataContextChanged += OnDataContextChanged;

            comboAssignDriver.Items.Add( DriverUndefined );

            if( false == DesignerProperties.GetIsInDesignMode( this ) )
            {
                foreach( string strDriver in LookupEmployee.GetAuthorizedNames( "Driver" ) )
                    comboAssignDriver.Items.Add( strDriver );
            }
        }


        void OnDataContextChanged( object sender, System.Windows.DependencyPropertyChangedEventArgs e )
        {
            Order order = e.NewValue as Order;

            if( order != null )
            {
                if( order.DeliveryDriver == null )
                    order.DeliveryDriver = DriverUndefined;
            }
        } 
    }
}
